package config;

import define.ErrorDefine;
import main.ErrorException;

public class ConfigMaker
{
	public ConfigMaker(String[] strs, int start, int end, int position) throws ErrorException
	{
		for(int i = start; i <= end; i += 2)
		{
			String name = checkStr(strs[i]);
			if(name == null)
			{
				throw new ErrorException(ErrorDefine.E_CONFIG_WRONG_ERROR, strs[i], position);
			}
			ConfigType ct = ConfigType.getConfig(name);
			if(ct == null)
			{
				throw new ErrorException(ErrorDefine.E_NO_CONFIG_ERROR, name, position);
			}
			if(i + 1 > end)
			{
				throw new ErrorException(ErrorDefine.E_MISS_CONFIG_ERROR, strs[i], position);
			}
			ct.setValue(strs[i + 1], position);
		}
	}
	
	private String checkStr(String text)
	{
		if(text.length() <= 1)
		{
			return null;
		}
		if(text.charAt(0) != '-')
		{
			return null;
		}
		return text.substring(1);
	}
}
